/*
 * @lc app=leetcode.cn id=50 lang=cpp
 *
 * [50_2] 字符串中的第一个唯一字符
 */

// @lc code=start

#include <queue>
#include <unordered_map>
#include <vector>

class Solution
{
 public:
  unordered_map<char, int> count;
  queue<char> q;

  // Insert one char from stringstream
  void insert(char ch)
  {
    if (++count[ch] > 1)  // ++count[ch]每次都会运行
    {
      while (q.size() && count[q.front()] > 1) q.pop();
    }
    else
    {
      q.push(ch);
    }
  }

  // return the first appearence once char in current stringstream
  char firstAppearingOnce()
  {
    if (q.empty()) return '#';
    return q.front();
  }
};
// @lc code=end
